//
//  MainViewController.m
//  SeePicture
//
//  Created by cocoazxj@163.com on 15/3/23.
//  Copyright (c) 2015年 handcool. All rights reserved.
//

#import "MainViewController.h"

@interface MainViewController ()
@property (nonatomic, strong) IBOutlet UIButton *btn_left;
@property (nonatomic, strong) IBOutlet UIButton *btn_right;
@property (nonatomic, strong) IBOutlet UILabel *lb_num;
@property (nonatomic, strong) IBOutlet UILabel *lb_profile;
@property (nonatomic, strong) IBOutlet UIImageView *iv_image;
@property (nonatomic, strong) NSArray *mArray;
@property (nonatomic, assign) int mIndex;
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 取出.plist文件路径
    NSString *string = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
    // 存入数组当中去。
    self.mArray = [NSArray arrayWithContentsOfFile:string];
    
    NSLog(@"--------------%d",self.mIndex);
    [self changeImage];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)changeImage
{
    [self.lb_num setText:[NSString stringWithFormat:@"%d/%lu",self.mIndex+1,(unsigned long)self.mArray.count]];
    [self.iv_image setImage:[UIImage imageNamed:self.mArray[self.mIndex][@"name"]]];
    [self.lb_profile setText:self.mArray[self.mIndex][@"profile"]];
    self.btn_left.enabled = (self.mIndex != 0);
    self.btn_right.enabled = (self.mIndex != 4);
}

- (IBAction)leftButtonClicked:(id)sender
{
    self.mIndex -- ;
    [self changeImage];
}

- (IBAction)rightButtonClicked:(id)sender
{
    self.mIndex ++ ;
    [self changeImage];
}
@end
